home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / emacs / emacs1857 / bin_d2.zoo / lisp / picture.el < prev    next >
Lisp/Scheme  |  1991-12-02  |  23KB  |  564 lines

  1. ;; "Picture mode" -- editing using quarter-plane screen model.
  2. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  3. ;; Principal author K. Shane Hartman
  4.  
  5. ;; This file is part of GNU Emacs.
  6.  
  7. ;; GNU Emacs is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 1, or (at your option)
  10. ;; any later version.
  11.  
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ;; GNU General Public License for more details.
  16.  
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  19. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22. (provide 'picture)
  23.  
  24. (defun move-to-column-force (column)
  25.   "Move to column COLUMN in current line.
  26. Differs from move-to-column in that it creates or modifies whitespace
  27. if necessary to attain exactly the specified column."
  28.   (move-to-column column)
  29.   (let ((col (current-column)))
  30.     (if (< col column)
  31.     (indent-to column)
  32.       (if (and (/= col column)
  33.            (= (preceding-char) ?\t))
  34.       (let (indent-tabs-mode)
  35.         (delete-char -1)
  36.             (indent-to col)
  37.             (move-to-column column))))))
  38.  
  39.  
  40. ;; Picture Movement Commands
  41.  
  42. (defun picture-end-of-line (&optional arg)
  43.   "Position point after last non-blank character on current line.
  44. With ARG not nil, move forward ARG - 1 lines first.
  45. If scan reaches end of buffer, stop there without error."
  46.   (interactive "P")
  47.   (if arg (forward-line (1- (prefix-numeric-value arg))))
  48.   (beginning-of-line)
  49.   (skip-chars-backward " \t" (prog1 (point) (end-of-line))))
  50.  
  51. (defun picture-forward-column (arg)
  52.   "Move cursor right, making whitespace if necessary.
  53. With argument, move that many columns."
  54.   (interactive "p")
  55.   (move-to-column-force (+ (current-column) arg)))
  56.  
  57. (defun picture-backward-column (arg)
  58.   "Move cursor left, making whitespace if necessary.
  59. With argument, move that many columns."
  60.   (interactive "p")
  61.   (move-to-column-force (- (current-column) arg)))
  62.  
  63. (defun picture-move-down (arg)
  64.   "Move vertically down, making whitespace if necessary.
  65. With argument, move that many lines."
  66.   (interactive "p")
  67.   (let ((col (current-column)))
  68.     (picture-newline arg)
  69.     (move-to-column-force col)))
  70.  
  71. (defconst picture-vertical-step 0
  72.   "Amount to move vertically after text character in Picture mode.")
  73.  
  74. (defconst picture-horizontal-step 1
  75.   "Amount to move horizontally after text character in Picture mode.")
  76.  
  77. (defun picture-move-up (arg)
  78.   "Move vertically up, making whitespace if necessary.
  79. With argument, move that many lines."
  80.   (interactive "p")
  81.   (picture-move-down (- arg)))
  82.  
  83. (defun picture-movement-right ()
  84.   "Move right after self-inserting character in Picture mode."
  85.   (interactive)
  86.   (picture-set-motion 0 1))
  87.  
  88. (defun picture-movement-left ()
  89.   "Move left after self-inserting character in Picture mode."
  90.   (interactive)
  91.   (picture-set-motion 0 -1))
  92.  
  93. (defun picture-movement-up ()
  94.   "Move up after self-inserting character in Picture mode."
  95.   (interactive)
  96.   (picture-set-motion -1 0))
  97.  
  98. (defun picture-movement-down ()
  99.   "Move down after self-inserting character in Picture mode."
  100.   (interactive)
  101.   (picture-set-motion 1 0))
  102.  
  103. (defun picture-movement-nw ()
  104.   "Move up and left after self-inserting character in Picture mode."
  105.   (interactive)
  106.   (picture-set-motion -1 -1))
  107.  
  108. (defun picture-movement-ne ()
  109.   "Move up and right after self-inserting character in Picture mode."
  110.   (interactive)
  111.   (picture-set-motion -1 1))
  112.  
  113. (defun picture-movement-sw ()
  114.   "Move down and left after self-inserting character in Picture mode."
  115.   (interactive)
  116.   (picture-set-motion 1 -1))
  117.  
  118. (defun picture-movement-se ()
  119.   "Move down and right after self-inserting character in Picture mode."
  120.   (interactive)
  121.   (picture-set-motion 1 1))
  122.  
  123. (defun picture-set-motion (vert horiz)
  124.   "Set VERTICAL and HORIZONTAL increments for movement in Picture mode.
  125. The mode line is updated to reflect the current direction."
  126.   (setq picture-vertical-step vert
  127.     picture-horizontal-step horiz)
  128.   (setq mode-name
  129.     (format "Picture:%s"
  130.         (car (nthcdr (+ 1 (% horiz 2) (* 3 (1+ (% vert 2))))
  131.                  '(nw up ne left none right sw down se)))))
  132.   ;; Kludge - force the mode line to be updated.  Is there a better
  133.   ;; way to this?
  134.   (set-buffer-modified-p (buffer-modified-p))
  135.   (message ""))
  136.  
  137. (defun picture-move ()
  138.   "Move in direction of  picture-vertical-step  and  picture-horizontal-step."
  139.   (picture-move-down picture-vertical-step)
  140.   (picture-forward-column picture-horizontal-step))
  141.  
  142. (defun picture-motion (arg)
  143.   "Move point in direction of current picture motion in Picture mode.
  144. With ARG do it that many times.  Useful for delineating rectangles in
  145. conjunction with diagonal picture motion.
  146. Do \\[command-apropos]  picture-movement  to see commands which control motion."
  147.   (interactive "p")
  148.   (picture-move-down (* arg picture-vertical-step))
  149.   (picture-forward-column (* arg picture-horizontal-step)))
  150.  
  151. (defun picture-motion-reverse (arg)
  152.   "Move point in direction opposite of current picture motion in Picture mode.
  153. With ARG do it that many times.  Useful for delineating rectangles in
  154. conjunction with diagonal picture motion.
  155. Do \\[command-apropos]  picture-movement  to see commands which control motion."
  156.   (interactive "p")
  157.   (picture-motion (- arg)))
  158.  
  159.  
  160. ;; Picture insertion and deletion.
  161.  
  162. (defun picture-self-insert (arg)
  163.   "Insert this character in place of character previously at the cursor.
  164. The cursor then moves in the direction you previously specified
  165. with the commands picture-movement-right, picture-movement-up, etc.
  166. Do \\[command-apropos]  picture-movement  to see those commands."
  167.   (interactive "p")
  168.   (while (> arg 0)
  169.     (setq arg (1- arg))
  170.     (move-to-column-force (1+ (current-column)))
  171.     (delete-char -1)
  172.     (insert last-input-char)
  173.     (forward-char -1)
  174.     (picture-move)))
  175.  
  176. (defun picture-clear-column (arg)
  177.   "Clear out ARG columns after point without moving."
  178.   (interactive "p")
  179.   (let* ((opoint (point))
  180.      (original-col (current-column))
  181.      (target-col (+ original-col arg)))
  182.     (move-to-column-force target-col)
  183.     (delete-region opoint (point))
  184.     (save-excursion
  185.      (indent-to (max target-col original-col)))))
  186.  
  187. (defun picture-backward-clear-column (arg)
  188.   "Clear out ARG columns before point, moving back over them."
  189.   (interactive "p")
  190.   (picture-clear-column (- arg)))
  191.  
  192. (defun picture-clear-line (arg)
  193.   "Clear out rest of line; if at end of line, advance to next line.
  194. Cleared-out line text goes into the kill ring, as do
  195. newlines that are advanced over.
  196. With argument, clear out (and save in kill ring) that many lines."
  197.   (interactive "P")
  198.   (if arg
  199.       (progn
  200.        (setq arg (prefix-numeric-value arg))
  201.        (kill-line arg)
  202.        (newline (if (> arg 0) arg (- arg))))
  203.     (if (looking-at "[ \t]*$")
  204.     (kill-ring-save (point) (progn (forward-line 1) (point)))
  205.       (kill-region (point) (progn (end-of-line) (point))))))
  206.  
  207. (defun picture-newline (arg)
  208.   "Move to the beginning of the following line.
  209. With argument, moves that many lines (up, if negative argument);
  210. always moves to the beginning of a line."
  211.   (interactive "p")
  212.   (if (< arg 0)
  213.       (forward-line arg)
  214.     (while (> arg 0)
  215.       (end-of-line)
  216.       (if (eobp) (newline) (forward-char 1))
  217.       (setq arg (1- arg)))))
  218.  
  219. (defun picture-open-line (arg)
  220.   "Insert an empty line after the current line.
  221. With positive argument insert that many lines."
  222.   (interactive "p")
  223.   (save-excursion
  224.    (end-of-line)
  225.    (open-line arg)))
  226.  
  227. (defun picture-duplicate-line ()
  228.   "Insert a duplicate of the current line, below it."
  229.   (interactive)
  230.   (save-excursion
  231.    (let ((contents
  232.       (buffer-substring
  233.        (progn (beginning-of-line) (point))
  234.        (progn (picture-newline 1) (point)))))
  235.      (forward-line -1)
  236.      (insert contents))))
  237.  
  238.  
  239. ;; Picture Tabs
  240.  
  241. (defvar picture-tab-chars "!-~"
  242.   "*A character set which controls behavior of commands
  243. \\[picture-set-tab-stops] and \\[picture-tab-search].  It is NOT a
  244. regular expression, any regexp special characters will be